//
//  BaseIMTableViewCell.m
//  markmap
//
//  Created by 甘世清 on 2024/5/19.
//

#import "BaseIMTableViewCell.h"

@implementation BaseIMTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)baseSQ_Style:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(6);
    }];
    [self.contentView addSubview:self.avatarImageView];
    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(48);
        make.left.equalTo(self.contentView).offset(12);
        make.top.equalTo(self.contentView).offset(6);
    }];
}
- (void)setModel:(IMMessageModel *)model{
    _model = model;
    if (model.isBlack) {
        self.blackImageView.hidden = NO;
    } else {
        self.blackImageView.hidden = YES;
    }
    [self.avatarImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        if (model.sendType) {
            make.left.equalTo(self.contentView).offset(12);
        } else {
            make.left.equalTo(self.contentView).offset(SCREEN_WIDETH-48-12);
        }
        if (model.isShowTime) {
            make.top.equalTo(self.contentView).offset(30);
        } else {
            make.top.equalTo(self.contentView).offset(6);
        }
    }];
    self.timeLabel.hidden = !model.isShowTime;
    [self.avatarImageView.headerImage sd_setImageWithURL:SQURLImage(model.portrait) placeholderImage:SQGetImage(@"zanwutouxiang")];
    self.timeLabel.text = [Manager SQ_getTimeString:model.time];
}
-(void)SQ_headerViewBtnClick{
    PeopleDetailViewController * vc = [[PeopleDetailViewController alloc]init];
    vc.uid = self.model.froms;
    [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.textColor = SQColorF5F5F5;
        _timeLabel.font = FONT_REGULAR(12);
    }
    return _timeLabel;
}

- (HeaderView *)avatarImageView{
    if (!_avatarImageView) {
        _avatarImageView = [[HeaderView alloc]init];
        _avatarImageView.clipsToBounds = YES;
        _avatarImageView.layer.cornerRadius = 24;
        _avatarImageView.layer.masksToBounds = YES;
        [_avatarImageView.btn addTarget:self action:@selector(SQ_headerViewBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _avatarImageView.headerImage.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _avatarImageView;
}
- (UIImageView *)blackImageView{
    if (!_blackImageView) {
        _blackImageView = [[UIImageView alloc]init];
        _blackImageView.image = SQGetImage(@"xiaoxifasongshibai");
        _blackImageView.contentMode = UIViewContentModeScaleAspectFit;
        _blackImageView.hidden = YES;
    }
    return _blackImageView;
}
@end
